// #ifndef VUE3
import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import * as utils from './utils/index.js'

export function createApp() {
  const app = createSSRApp(App)
  const pinia = createPinia()
  
  // 注册全局工具库
  app.config.globalProperties.$utils = utils
  
  // 注册全局方法
  app.config.globalProperties.$showToast = (title, icon = 'none') => {
    uni.showToast({
      title,
      icon
    })
  }
  
  app.config.globalProperties.$showLoading = (title = '加载中...') => {
    uni.showLoading({
      title
    })
  }
  
  app.config.globalProperties.$hideLoading = () => {
    uni.hideLoading()
  }
  
  app.config.globalProperties.$navigateTo = (url, params = {}) => {
    const query = Object.keys(params).map(key => `${key}=${params[key]}`).join('&')
    const fullUrl = query ? `${url}?${query}` : url
    uni.navigateTo({
      url: fullUrl
    })
  }
  
  app.use(pinia)
  
  return {
    app
  }
}
// #endif